package com.huidao.servlet.order;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Goods;
import com.huidao.entity.Order;
import com.huidao.entity.User;
import com.huidao.service.OrderService;
import com.huidao.service.OrderServiceImpl;

/**
 * Servlet implementation class AddOrderServlet
 */
public class AddOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Order order=new Order();
		order.setGoodsNum(Long.parseLong(request.getParameter("num")));
		Goods goods=new Goods();
		goods.setGoodsId(Long.parseLong(request.getParameter("goodsId")));
		Long goodsId=Long.parseLong(request.getParameter("goodsId"));
		order.setGoods(goods);
		User user=(User) request.getSession().getAttribute("user");
		order.setUser(user);
		OrderService o=new OrderServiceImpl();
		String data=o.buyOrder(order);
		if(data.equals("")){
			request.setAttribute("goodsId", goodsId);
			request.getRequestDispatcher("GetOrderListServlet").forward(request, response);
		}else{
			response.getWriter().print(data);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
